<?php
/**
 * Zeed Platform Project
 * Based on Zeed Framework & Zend Framework.
 *
 * LICENSE
 * http://www.zeed.com.cn/license/
 *
 * @category Zeed
 * @package Zeed_ChangeMe
 * @subpackage ChangeMe
 * @copyright Copyright (c) 2010 Zeed Technologies PRC Inc. (http://www.zeed.com.cn)
 * @author Zeed Team (http://blog.zeed.com.cn)
 * @since 2010-12-6
 * @version SVN: $Id$
 */
class ArchiveAdminAbstract extends AdminAbstract
{
    /**
     * 初始化新建文件夹
     */
    public function initFolder($sn, $card_id, $attachments_img = null, $attachments_audio = null, $attachments_video = null)
    {
        $timenow = Util_Timer::getMicrotime();
        
        /* 创建图片型文件夹 */
        $params_addfolder_image = array(
                'userid' => $this->_userid_fs,
                'title' => date('Y-m-d', intval($timenow / 1000)) . '_image_' . $card_id,
                'sn' => $sn,
                'card_id' => $card_id
        );
        $folder_info_image = Attachment_Folder_Add::run($params_addfolder_image);
        
        /* 写入附件与文件夹的关系 */
        if ($attachments_img && $folder_info_image['status'] == 0) {
            $attachments_img_arr = explode(',', $attachments_img);
            foreach ($attachments_img_arr as $k => $v) {
                $set_image = array(
                        'folder_hid' => $folder_info_image['data']['hid'],
                        'mtime' => $timenow
                );
                Attachment_Model_Content::instance()->updateForEntity($set_image, $v);
            }
            
            /* 更新文件夹信息 */
            $update_folder_image = array('is_has_children' => 1);
            Attachment_Model_Folder::instance()->updateForEntity($update_folder_image, $folder_info_image['_id']);
        }
        
        /* 创建音频型文件夹 */
        $params_addfolder_audio = array(
                'userid' => $this->_userid_fs,
                'title' => date('Y-m-d', intval($timenow / 1000)) . '_audio_' . $card_id,
                'sn' => $sn,
                'card_id' => $card_id
        );
        $folder_info_audio = Attachment_Folder_Add::run($params_addfolder_audio);
        
        /* 写入附件与文件夹的关系 */
        if ($attachments_audio && $folder_info_audio['status'] == 0) {
            $attachments_audio_arr = explode(',', $attachments_audio);
            foreach ($attachments_audio_arr as $k => $v) {
                $set_audio = array(
                        'folder_hid' => $folder_info_audio['data']['hid'],
                        'mtime' => $timenow
                );
                Attachment_Model_Content::instance()->updateForEntity($set_audio, $v);
            }
            
            /* 更新文件夹信息 */
            $update_folder_audio = array('is_has_children' => 1);
            Attachment_Model_Folder::instance()->updateForEntity($update_folder_audio, $folder_info_audio['_id']);
        }
        
        /* 创建视频型文件夹 */
        $params_addfolder_video = array(
                'userid' => $this->_userid_fs,
                'title' => date('Y-m-d', intval($timenow / 1000)) . '_video_' . $card_id,
                'sn' => $sn,
                'card_id' => $card_id
        );
        $folder_info_video = Attachment_Folder_Add::run($params_addfolder_video);
        
        /* 写入附件与文件夹的关系 */
        if ($attachments_video && $folder_info_video['status'] == 0) {
            $attachments_video_arr = explode(',', $attachments_video);
            foreach ($attachments_video_arr as $k => $v) {
                $set_video = array(
                        'folder_hid' => $folder_info_video['data']['hid'],
                        'mtime' => $timenow
                );
                Attachment_Model_Content::instance()->updateForEntity($set_video, $v);
            }
            
            /* 更新文件夹信息 */
            $update_folder_video = array('is_has_children' => 1);
            Attachment_Model_Folder::instance()->updateForEntity($update_folder_video, $folder_info_video['_id']);
        }
    }
}

// End ^ Native EOL ^ UTF-8